package cn.edu.swu.dlx;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class BookResultSetVisitor implements ResultSetVisitor<Book>{

    @Override
    public List<Book> visit(ResultSet resultSet) {

        List<Book> books = new ArrayList<>();
        try{
            while(resultSet.next()){
                Book book = new Book();
                book.setId(resultSet.getInt("id"));
                book.setName(resultSet.getString("name"));
                book.setAuthor(resultSet.getString("author"));
                book.setPrice(resultSet.getDouble("price"));
                book.setPublish(resultSet.getDate("publish"));
                books.add(book);
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return books;
    }
}
